import dayjs from "dayjs"
import type { ConfigType } from "dayjs"
import 'dayjs/locale/zh-cn';

export function setupDayjs() {
  dayjs.locale('zh-cn');
}

export const longWeeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]

const DateFormat = {
  long: "YYYY-MM-DDTHH:mm:ss",
  default: "YYYY-MM-DD HH:mm:ss",
  short: "YYYY-MM-DD"
} as const

type DateFormatTemplate = keyof typeof DateFormat | (string & {})

export function dateFormat(date?: ConfigType, format?: DateFormatTemplate): string {
  return dayjs(date).format(format ? DateFormat[format] ?? format : DateFormat.default)
}

export type Dayjs = dayjs.Dayjs;

export {
  dayjs as dateUtil
}
